package com.x.example.page;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.x.example.demo.WebPage;
import com.x.uikit.page.XLifecycle;
import com.x.uikit.router.XRoute;

public class WebActivity extends AppCompatActivity {
    WebPage mWebPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XRoute route = PagesRouteHandler.getRoute(getIntent());
        mWebPage = new WebPage(this);
        Bundle bundle = new Bundle();
        bundle.putString("url", route.path);
        mWebPage.setArgument(bundle);
        setContentView(mWebPage);
        mWebPage.getLifecycle().update(XLifecycle.State.CREATE);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mWebPage.getLifecycle().update(XLifecycle.State.START);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mWebPage.getLifecycle().update(XLifecycle.State.RESUME);
    }

    @Override
    protected void onPause() {
        mWebPage.getLifecycle().update(XLifecycle.State.PAUSE);
        super.onPause();
    }

    @Override
    protected void onStop() {
        mWebPage.getLifecycle().update(XLifecycle.State.STOP);
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        mWebPage.getLifecycle().update(XLifecycle.State.DESTROY);
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        if (!mWebPage.onBackPressed()) {
            super.onBackPressed();
        }
    }
}